Export Full Asset as CSV
Introduction
An asset within Assetic may be comprised of several elements, as outlined in the article Asset Integration Overview. The elements may include:
- Components
- Component Dimensions
- Location including spatial definition
- Service Criteria
The Assetic Python SDK provides a toolset to extract all of these elements as a single record.
One such tool is the assetic.FullAssetExport() tool (introduced in Assetic Python SDK version 2018.11.1.2) which will extract to csv one or more assets from Assetic as a single record including all elements if requested.
This export tool may be used to generate correctly formatted files for upload into other systems, such as Technology One.
Usage Notes:
It is typically best to use this tool on a per Asset Category basis as each Asset Category may have a different component and network measure structure.
This tool is not intended for bulk export process of thousands of asset records. It's primary use is to provide incremental exports of small numbers of assets. Please use the Bulk Export tools for this purpose
Configuration File
The tool is configured using a csv file to define the required fields, and the header label to use for that field in the output file.
The csv configuration file has the following structure:
Column Name | Description | Samples |
Output Field Name | The value to use for the field header in the csv output | Asset Name |
Asset Level |
Define in which Assetic asset element contains the field to export. Note that "constant" is a special level type. If defined, the value is not derived from Assetic, but is instead hard coded in the "constant" column of this configuration file. |
Use one of: "asset" "component" "dimensions" "location" "constant" |
Assetic Field Name |
The internal name of the field to export (not the label presented in the Assetic UI). These field names are described in the introductory article Asset Integration Overview Note that if the "Asset Level" is "location" there is the option to concatenate the individual address elements to return the full formatted address. To achieve this specify the field name as "Address". |
e.g . "AssetName" |
Component Type | If the field is a component field define the component type that the field belongs to. Since there may be multiple components it is necessary to specify which component by component type | e.g. "Main" |
Network Measure Type | If the "Asset Level" is "dimensions" it is necessary to specify the "Component Type" that contains the network measure. Is is also necessary to specify the "Network Measure Type" and the network measure "Record Type" to uniquely identify the network measure to export | Area |
NM Record Type | f the "Asset Level" is "dimensions" it is necessary to specify the "Component Type" that contains the network measure. Is is also necessary to specify the "Network Measure Type" and the network measure "Record Type" to uniquely identify the network measure to export | "Addition" or "Info" |
Constant | Apply a constant value for the field rather than getting the value from Assetic. This column will have the same value for all records | "Code123" |
Field Size | This is not implemented, but may be implemented in the future to truncate the field to the specified field length | 255 |
The following is a sample csv configuration file:
Output Field Name,Asset Level,Assetic Field Name,Component Type,Network Measure Type,NM Record Type,Constant,Field Size ASSETOPERSTATUS,constant,,,,,I, REGNAME,constant,,,,,Asset, DESCR,asset,AssetName,,,,,40 OPERATINGLDGCODE,constant,,,,,101830, OPERATINGACCOUNTNBR,constant,,,,,PJ, SHORTDESCR,constant,,,,,Footpath,20 ASSETNBR,asset,AssetId,,,,, LONGDESCR,asset,SegmentNum,,,,,256 SELCODE15,asset,AcquiredFrom,,,,, ASSETSTAT,constant,,,,,NA, ASSETNBRUSERENTERED,constant,,,,,FP, USERFLD18,component,design_life,Main,,,, ASSETNBRGENCODE,constant,,,,,NA, ASSETTYPE,constant,,,,,S, DIM,dimensions,network_measure,Main,Area,Addition,, USERFLD18,location,Address,,,,,
Additional options
The assetic.FullAssetExport() tool allows the following additional configuration options:
- Output file location
- Specified when the tool is initialised, it defines the folder where the export files will be written to
On running the export the following keyword arguments are available (configuration template)
- config_file
- The name of the configuration file that defines the data to export
- output_file
- The name of the csv file to create
- prependrow
- A string that is inserted as the first row of the output file, before the header columns.
- postpendrow
- A string that is appended as a new row at the end of the csv file.
On running the export a filter is also required to restrict the assets returned
- asset_filter
- as an example "AssetCategory='Pathways'~and~LastModified~gte~'2018-03-22T11:39:36'" will return only those Pathway assets that have been modified since 2018-03-22 (22 March 2018). The article Search Filters and Pagination describes the syntax used for filtering
- export_defs
- A list of export configuration definitions (configuration template) may be provided. This supports requirements where the same set of assets needs to be written to two different files. Each configuration can specify different fields to write the each csv file
Run Export
The following script illustrates how to execute the process assetic.FullAssetExport(). In this instance a set of files for a Technology One Asset upload are generated
- # coding: utf-8
- """
- Assetic.TechOneAssetTemplate.py
- Extract new assets from Assetic and create upload templates
- """
- import assetic
- if __name__ == '__main__':
- # Assetic SDK instance
- asseticsdk = assetic.AsseticSDK(
- "C:/Users/kwilton/asseticCumberland.ini", None, "Info")
- export = assetic.FullAssetExport("c:/temp/T1upload")
- export_defs = list()
- export_def = {"config_file":
- "c:/temp/T1upload/building_attributes_config.csv",
- "output_file": "building_attributes.csv",
- "prependrow": 'FORMAT ASSET ATTRIBUTES',
- "postpendrow": None}
- # add config to list
- export_defs.append(export_def)
- export_def = {"config_file": "c:/temp/T1upload/building_detail_config.csv",
- "output_file": "building_detail.csv",
- "prependrow": 'FORMAT ASSET ATTRIBUTES',
- "postpendrow": None}
- # add config to list
- export_defs.append(export_def)
- # Define asset selection criteria and asset fields
- asset_filter = "AssetCategory='Buildings'" \
- "~and~LastModified~gte~'2018-03-22T11:39:36'"
- # initialise tool and initiate
- chk = export.export_asset(asset_filter, export_defs)
- print("Result: {0}".format(chk))